package com.lxyk.springcloud.controller;

import com.lxyk.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j//这个注解归属于Lombok，所以有了Lombok依赖就能使用这个注解 最主要目的是使用log 可以在网页打印信息
public class PaymentController {

    @Resource//作用和@Autowired一样  但是Resource是根据name注入 后者根据类注入 还有一个@Resources注解是注入多个
    private PaymentService paymentService;

    //成功接口
    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_Ok(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_Ok(id);
        log.info("result:"+result);
        return result;//因为有@RestController注解，返回的就是JSON
    }

    //超时接口
    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_Timeout(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_Timeout(id);
        log.info("result:"+result);
        return result;
    }

    // Hystrix 服务熔断案例
    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("*******result:"+result);
        return result;
    }

}
